"use strict";
var __importDefault = (this && this.__importDefault) || function (mod) {
    return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.getThemePreviewUrl = exports.getThemeJSONPath = void 0;
const findup_sync_1 = __importDefault(require("findup-sync"));
const urls_1 = require("../urls");
const environments_1 = require("../../constants/environments");
const config_1 = require("../../config");
function getThemeJSONPath(path) {
    return (0, findup_sync_1.default)('theme.json', {
        cwd: path,
        nocase: true,
    });
}
exports.getThemeJSONPath = getThemeJSONPath;
function getThemeNameFromPath(filePath) {
    const themeJSONPath = getThemeJSONPath(filePath);
    if (!themeJSONPath)
        return;
    const pathParts = themeJSONPath.split('/');
    if (pathParts.length < 2)
        return;
    return pathParts[pathParts.length - 2];
}
function getThemePreviewUrl(filePath, accountId) {
    const themeName = getThemeNameFromPath(filePath);
    if (!themeName)
        return;
    const baseUrl = (0, urls_1.getHubSpotWebsiteOrigin)((0, config_1.getConfigAccountEnvironment)(accountId) === 'qa'
        ? environments_1.ENVIRONMENTS.QA
        : environments_1.ENVIRONMENTS.PROD);
    return `${baseUrl}/theme-previewer/${accountId}/edit/${encodeURIComponent(themeName)}`;
}
exports.getThemePreviewUrl = getThemePreviewUrl;
